package com.vitogiovanni.tobook.utilities;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;

import com.vitogiovanni.tobook.R;

public class LocaleGridFotoAdapter extends ArrayAdapter<Bitmap> {

	private Context mContext;
	private List<Bitmap> listaFoto;

	public LocaleGridFotoAdapter(Context c, int resource, List<Bitmap> listaFoto) {
		super(c, resource, listaFoto);
		mContext = c;
		this.listaFoto = listaFoto;
	}
	
	@Override
	public int getCount() {
		return listaFoto.size();
	}
	
	private class ViewHolderGrid {
        ImageView fotoLocale;
    }
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolderGrid holder = null;
		
		LayoutInflater minflater = (LayoutInflater) mContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
		
		if (convertView == null) {
			convertView = minflater.inflate(R.layout.grid_foto_locale, null);
			holder = new ViewHolderGrid();
			holder.fotoLocale = (ImageView) convertView.findViewById(R.id.foto_locale_item);
			convertView.setTag(holder);
		}else {
			holder = (ViewHolderGrid) convertView.getTag();
		 }

		holder.fotoLocale.setImageBitmap(listaFoto.get(position));
		return convertView;
	}

}
